package com.fyakm.daodejing.stock.util;

import com.fyakm.daodejing.stock.domain.StockHistoryItem;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 股票历史数据工具类
 */
public class StockHistoryUtil {

    /** 将股票历史list按照日期进行切割
     *  只保留startDate到endDate之间的数据
     * @param historyItems 股票历史list
     * @param startDate 开始日期
     * @param endDate 结束日期
     * @return 切割后的股票历史list
     */
    public static List<StockHistoryItem> splitStockHistoryByDate(List<StockHistoryItem> historyItems, Date startDate, Date endDate) {
        List<StockHistoryItem> result = new ArrayList<>();
        for (StockHistoryItem historyItem : historyItems) {
            Date date = historyItem.getDate();
            if (date.compareTo(startDate) >= 0 && date.compareTo(endDate) <= 0) {
                result.add(historyItem);
            }
        }
        return result;

    }

}
